<?php

namespace Futures\Controller;
use Think\Controller;

/**
 *  代理商登录
 */
class AgentPublicController extends Controller {

	public function login(){
		if(IS_POST){
			/* 读取数据库中的配置 */
			$config	=	S('DB_CONFIG_DATA');
			if(!$config){
				$config	=	D('Config')->lists();
				S('DB_CONFIG_DATA',$config);
			}
			C($config); //添加配置
			$verify = $_POST['Verify'];			//获取验证码
			$username=$_POST['username'];		//获取用户名
			$password=$_POST['password'];		//获取密码
			$password_md = md5($password);
			/* 账户登录 */
			$User  = M('Futures_agent');
			$log = $User->where("user_name='".$username."'")->find();//查找判断数据库有没有此用户
			/* 登录用户 */
			if($log['password']==$password_md){
				//验证码验证
				/* $verify = check_verify($verify); */
				//if($verify){
					//获取头像
					$headimgurl = M('Follow')->where('id='.$log[user_id])->field('headimgurl')->find();
					$log['headimgurl'] = $headimgurl['headimgurl'];
					session(AGENT,$log);
					$this->success('登录成功！');
				/* }else{
					$error = "验证码错误";
					$this->error($error);
				} */
			}else{
				$error = "用户名或密码错误";
				$this->error($error);
			}
		}else{
			$this->display();
		}
	}
	/* //验证码生成
	public function verify(){
		$Verify = new \Think\Verify();
		$Verify->fontSize = 21;					//验证码字体大小
		$Verify->length = 4;					//验证码字数
		$Verify->useCurve = false;				//去除混淆曲线
		$Verify->useNoise = false;				//去除杂点
		$Verify->bg = array(243, 251, 254);		//背景颜色
		$Verify->entry(2);
	} */
	//退出登录
	public function out(){
		session(AGENT,null);
		$this->success('退出成功',U('AgentPublic/login'));
	}
}
